home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / LITTLE / P3SRC.ZIP / ATARI / RAY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  5.8 KB  |  285 lines

  1. /****************************************************************************
  2. *                ray.c
  3. *
  4. *  This module implements the code pertaining to rays.
  5. *
  6. *  from Persistence of Vision(tm) Ray Tracer
  7. *  Copyright 1996 Persistence of Vision Team
  8. *---------------------------------------------------------------------------
  9. *  NOTICE: This source code file is provided so that users may experiment
  10. *  with enhancements to POV-Ray and to port the software to platforms other 
  11. *  than those supported by the POV-Ray Team.  There are strict rules under
  12. *  which you are permitted to use this file.  The rules are in the file
  13. *  named POVLEGAL.DOC which should be distributed with this file. If 
  14. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  15. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  16. *  Forum.  The latest version of POV-Ray may be found there as well.
  17. *
  18. * This program is based on the popular DKB raytracer version 2.12.
  19. * DKBTrace was originally written by David K. Buck.
  20. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  21. *
  22. *****************************************************************************/
  23.  
  24. #include "frame.h"
  25. #include "vector.h"
  26. #include "povproto.h"
  27. #include "povray.h"
  28. #include "ray.h"
  29. #include "texture.h"
  30.  
  31.  
  32.  
  33. /*****************************************************************************
  34. * Local preprocessor defines
  35. ******************************************************************************/
  36.  
  37.  
  38.  
  39. /*****************************************************************************
  40. * Local typedefs
  41. ******************************************************************************/
  42.  
  43.  
  44.  
  45. /*****************************************************************************
  46. * Local variables
  47. ******************************************************************************/
  48.  
  49.  
  50.  
  51. /*****************************************************************************
  52. * Static functions
  53. ******************************************************************************/
  54.  
  55.  
  56.  
  57. /*****************************************************************************
  58. *
  59. * FUNCTION
  60. *
  61. *   Initialize_Ray_Containers
  62. *
  63. * INPUT
  64. *   
  65. * OUTPUT
  66. *   
  67. * RETURNS
  68. *   
  69. * AUTHOR
  70. *
  71. *   POV-Ray Team
  72. *   
  73. * DESCRIPTION
  74. *
  75. *   -
  76. *
  77. * CHANGES
  78. *
  79. *   -
  80. *
  81. ******************************************************************************/
  82.  
  83. void Initialize_Ray_Containers(Ray)
  84. RAY *Ray;
  85. {
  86.   Ray->Containing_Index = - 1;
  87. }
  88.  
  89.  
  90.  
  91. /*****************************************************************************
  92. *
  93. * FUNCTION
  94. *
  95. *   Copy_Ray_Containers
  96. *
  97. * INPUT
  98. *   
  99. * OUTPUT
  100. *   
  101. * RETURNS
  102. *   
  103. * AUTHOR
  104. *
  105. *   POV-Ray Team
  106. *
  107. * DESCRIPTION
  108. *
  109. *   -
  110. *
  111. * CHANGES
  112. *
  113. *   -
  114. *
  115. ******************************************************************************/
  116.  
  117. void Copy_Ray_Containers(Dest_Ray, Source_Ray)
  118. RAY *Dest_Ray, *Source_Ray;
  119. {
  120.   register int i;
  121.  
  122.   if ((Dest_Ray->Containing_Index = Source_Ray->Containing_Index) >= MAX_CONTAINING_OBJECTS)
  123.   {
  124.     Error("ERROR - Containing Index too high.\n");
  125.   }
  126.  
  127.   for (i = 0 ; i <= Source_Ray->Containing_Index; i++)
  128.   {
  129.     Dest_Ray->Containing_Textures[i] = Source_Ray->Containing_Textures[i];
  130.     Dest_Ray->Containing_Objects[i]  = Source_Ray->Containing_Objects[i];
  131.     Dest_Ray->Containing_IORs[i]     = Source_Ray->Containing_IORs[i];
  132.   }
  133. }
  134.  
  135.  
  136.  
  137. /*****************************************************************************
  138. *
  139. * FUNCTION
  140. *
  141. *   Ray_Enter
  142. *
  143. * INPUT
  144. *   
  145. * OUTPUT
  146. *   
  147. * RETURNS
  148. *   
  149. * AUTHOR
  150. *
  151. *   POV-Ray Team
  152. *   
  153. * DESCRIPTION
  154. *
  155. *   -
  156. *
  157. * CHANGES
  158. *
  159. *   Oct 1995 : Fixed bug with IOR assignment (only valid for plain textures) [DB]
  160. *
  161. ******************************************************************************/
  162.  
  163. void Ray_Enter(Ray, texture, object)
  164. RAY *Ray;
  165. TEXTURE *texture;
  166. OBJECT *object;
  167. {
  168.   register int index;
  169.  
  170.   if ((index = ++(Ray->Containing_Index)) >= MAX_CONTAINING_OBJECTS)
  171.   {
  172.     Error("Too many nested refracting objects.");
  173.   }
  174.  
  175.   Ray->Containing_Textures[index] = texture;
  176.  
  177.   if ((texture->Type == PLAIN_PATTERN) && (texture->Finish != NULL))
  178.   {
  179.     Ray->Containing_IORs[index] = texture->Finish->Index_Of_Refraction;
  180.   }
  181.   else
  182.   {
  183.     Ray->Containing_IORs[index] = Frame.Atmosphere_IOR;
  184.   }
  185.  
  186.   Ray->Containing_Objects[index] = object;
  187. }
  188.  
  189.  
  190.  
  191. /*****************************************************************************
  192. *
  193. * FUNCTION
  194. *
  195. *   Ray_Exit
  196. *
  197. * INPUT
  198. *   
  199. * OUTPUT
  200. *   
  201. * RETURNS
  202. *   
  203. * AUTHOR
  204. *
  205. *   POV-Ray Team
  206. *   
  207. * DESCRIPTION
  208. *
  209. *   Remove given entry from given ray's container.
  210. *
  211. * CHANGES
  212. *
  213. *   -
  214. *
  215. ******************************************************************************/
  216.  
  217. void Ray_Exit(Ray, nr)
  218. RAY *Ray;
  219. int nr;
  220. {
  221.   int i;
  222.  
  223.   for (i = nr; i < Ray->Containing_Index; i++)
  224.   {
  225.     Ray->Containing_Textures[i] = Ray->Containing_Textures[i+1];
  226.     Ray->Containing_Objects[i]  = Ray->Containing_Objects[i+1];
  227.     Ray->Containing_IORs[i]     = Ray->Containing_IORs[i+1];
  228.   }
  229.  
  230.   if (--(Ray->Containing_Index) < - 1)
  231.   {
  232.     Error("Too many exits from refractions.");
  233.   }
  234. }
  235.  
  236.  
  237.  
  238. /*****************************************************************************
  239. *
  240. * FUNCTION
  241. *
  242. *   Texture_In_Ray_Container
  243. *
  244. * INPUT
  245. *
  246. * OUTPUT
  247. *
  248. * RETURNS
  249. *
  250. * AUTHOR
  251. *
  252. *   Dieter Bayer
  253. *
  254. * DESCRIPTION
  255. *
  256. *   Test if a given texture is in the container of a given ray.
  257. *
  258. * CHANGES
  259. *
  260. *   Mar 1996 : Creation.
  261. *
  262. ******************************************************************************/
  263.  
  264. int Texture_In_Ray_Container(Ray, Texture)
  265. RAY *Ray;
  266. TEXTURE *Texture;
  267. {
  268.   int i, found;
  269.  
  270.   found = -1;
  271.  
  272.   for (i = 0; i <= Ray->Containing_Index; i++)
  273.   {
  274.     if (Texture == Ray->Containing_Textures[i])
  275.     {
  276.       found = i;
  277.  
  278.       break;
  279.     }
  280.   }
  281.  
  282.   return(found);
  283. }
  284.  
  285.